#include<cstdio>
#include<cmath>
long long  f[31301];
int d[10]={0,1,10,100,1000,10000,100000};
int main()
{
	freopen("test.in","r",stdin);
	f[1]=1;
	int k=1,p=1;
	for(int i=2;i<=31300;i++)
	{
		p=(int)log10((double)i)+1;
		k+=p;
		f[i]=f[i-1]+k;
	}
	int t,n;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d",&n);
		int l=1,r=31300,mid;
		while(l<=r)
		{
			mid=(l+r)/2;
			if(f[mid]<n)l=mid;
			if(f[mid]>n)r=mid;
			if(f[mid]==n)break;
			if(l+1==r&&f[l]<n&&f[r]>=n){mid=r;break;}
		}
//		printf("n=%d  mid=%d f[mid]=%d\n",n,mid,f[mid]);
		int c=0,ans,tem=n-f[mid-1];
		for(int i=1;i<=33000;i++)
		{

			int x=i;
			bool find=false;
			int a[10],k=0;
			while(x>0)
			{
				k++;
				a[k]=x%10;
				x/=10;
			}
			for(int j=k;j>=1;j--)	
			{
				c++;
				if(c==tem){ans=a[j];find=true;break;}
			}
			if(find)break;
		}

		printf("%d\n",ans);

	}
	
	return 0;
}
